package com.mobi.spring1.Sever.impl;

import com.mobi.spring1.Sever.Sever;
import com.mobi.spring1.dao.LoginDao;
import com.mobi.spring1.pojo.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginSever implements Sever {
    @Autowired
    LoginDao dao;

    private Login login;

    @Override
    public void add(Object o) {
        login=(Login) o;
        dao.save(login);
    }

    @Override
    public void del(Integer id) {
        dao.deleteById(id);
    }

    @Override
    public void update(Object o) {
        login=(Login) o;
        dao.save(login);
    }

    @Override
    public Object findById(Integer id) {
        return dao.findById(id);
    }

    @Override
    public Object findAll() {
        return dao.findAll();
    }

    public boolean findByUsername(String username,String password){
        Login byUsername = dao.findByUsername(username);
        if (byUsername==null){
            return false;
        }
        if (password.equals(byUsername.getPassword())){
            return true;
        }
        return false;
    }

    public Login findByUsername(String username){
        Login byUsername = dao.findByUsername(username);
        if (byUsername==null) {
            return null;
        }
        return byUsername;
    }


}
